<?php

	$paging=new paging();
	$mod = $_GET['mod'];
	$curpg = $_GET['curpg'];
	$curpg=(isset($curpg))?$curpg:1;
	$gotopage='?mod='.$mod."&act=list";
	
	$where = "";
	$idcat = 0;
	if(isset($_POST['idcat']))
	{
		$idcat = $_POST['idcat'];
		if($idcat!=0) $where = " where idcat = '$idcat'";
	}
	elseif(isset($_GET['idcat']))
	{
		$idcat = $_GET['idcat'];
		if($idcat!=0) $where = " where idcat = '$idcat'";
	}
		
	$db = new MySQL();
	$table = "faq_item";
    $query = "select * from $table $where";
	$sql = $db->select($query);
	$totalrows=$db->numrows($sql);

    $query = "select * from $table $where order by orderId, id asc limit ".(($curpg-1)*$perpage).", ".$perpage;
    $sql = $db->select($query);

?>


<script type="text/javascript">	
	function add(idcat) {
		window.location.href = "?mod=<?=$mod?>&act=edit&idcat="+idcat;
	}

	function edit(id) {
		window.location.href = "?mod=<?=$mod?>&act=edit&id="+id;
	}

	function del(id) {
		var frm = document.frmlist;
		bok=confirm("<?=$msg_deleteone?>");
		if (bok) {		
			frm.listid.value = id + ",";			
			frm.action = "?mod=<?=$mod?>&act=process";
			frm.submit();
		}
	}
	
	function delall(id) {
		var frm = document.frmlist;
		if (<?=$totalrows?> != 0)		
		frm.listid.value=selectid(frm.chkid);		
		if (frm.listid.value=="") {		
			if (<?=$totalrows?> != 0)				
			alert("<?=$msg_ask_select?>");
		}	
		else {
			bok=confirm("<?=$msg_conf_del?>");
			if (bok) {					
				frm.action = "?mod=<?=$mod?>&act=process";				
				frm.submit();
			}
		}		
	}
	
	function show(id){
	
		
		var frm=document.frmlist;		
			frm.action="?mod=<?=$mod?>&act=list&id="+id;
			frm.method="POST";
			frm.submit();
		
	}
	
	function submitfrm(idcat) {			
		window.location.href = "?mod=<?=$mod?>&act=list&idcat="+idcat;
	}
	
	
</script>
<script type="text/javascript" src="scriptaculous/prototype.js"></script>  
    <script type="text/javascript" src="scriptaculous/scriptaculous.js"></script>  
    <script type="text/javascript">  
    //<![CDATA[  
        document.observe('dom:loaded', function() {  
            var changeEffect;  
            Sortable.create('sortlist', { tag: 'li', overlap:'horizontal',constraint:false,   
                onChange: function(item) {  
                    var list = Sortable.options(item).element;  
                    //$('changeNotification').update(Sortable.serialize(list).escapeHTML());  
                    if(changeEffect) changeEffect.cancel();  
                    changeEffect = new Effect.Highlight('changeNotification', {restoreColor:"transparent" });  
                },  
                      
                onUpdate: function() {  
                    new Ajax.Request("<?=$mod?>_order.php", {  
                        method: "post",  
                        onLoading: function(){$('activityIndicator').show()},  
                        onLoaded: function(){$('activityIndicator').hide()},  
                        parameters: { data: Sortable.serialize("sortlist") }  
                    });  
                }                 
            });  
        });  
    // ]]>  
    </script>  
	

<form name="frmlist" method="post" action="">		
<table width="100%" border="0" cellpadding="0" cellspacing="0">
	<tr>
	  <td align="left" valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0">
		  <tr>
			<td width="34"><img src="<?=APPLICATION_SITEADMIN_URL?>images/cor_data_top_l.gif" alt="tl" width="34" height="19" /></td>
			<td class="toptborder">&nbsp;</td>
			<td width="20"><img src="<?=APPLICATION_SITEADMIN_URL?>images/cor_data_top_r.gif" alt="tr" /></td>
		  </tr>
	  </table></td>
	</tr>
	<tr>
	  <td><table width="100%" border="0" cellspacing="0" cellpadding="0">
		 
		  <tr>
			<td width="10" class="leftborder">&nbsp;</td>
			<td><table width="100%" border="0" cellpadding="0" cellspacing="0" class="dataBack">
				  <tr>
				  <td width="27%" height="36" class="titleOrange">FAQ Items</td>
				  <td align="right" class="titleOrange">
				  <strong>Categories :</strong> 
				    <select name="cbidcat" onchange="submitfrm(this.value);">
					<option value="0">All Categories</option>
					<? 
						$qr_cat = "select * from faq_cat order by orderId ";
						$re_cat = $db->select($qr_cat);
						while($tt_cat = $db->fetch($re_cat))
						{
							echo '<option value="'.$tt_cat['id'].'" ';
							if($idcat == $tt_cat['id']) echo " selected";
							echo ' > '.$tt_cat['title'].'</option>';
						}
					?>									
					</select>
				  </td>
			    </tr>
				<tr>
				  <td height="7" colspan="2" background="images/cor_data_line1.gif"></td>
				</tr>
				<tr>
				  <td colspan="2">
				  <table width="100%" border="0" cellspacing="0" cellpadding="0">
					
					  <tr>
						<td colspan="5" class="dataBack2"><table width="100%" border="0" align="left" cellpadding="0" cellspacing="0">
							<tr>
							  <td align="left" valign="top" ><table width="100%" border="0" cellspacing="0">
								  <tr>
									<td><table width="100%" border="0" cellspacing="0">
										<tr>
										  <td width="25%" align="left" valign="bottom"><a href="javascript:docheckallnew(false, document.frmlist.chkid)" >Deselect All</a> | <a href="javascript:docheckallnew(true, document.frmlist.chkid)" >Select All</a> </td>
										  <td width="54%" align="left" valign="bottom">													  </td>
										  <td align="right" valign="top">
										 <img src="images/icons/add.png" onclick="add('<?=$idcat?>');"  class="pointer"/> <img src="images/icons/delete.png" onclick="delall();" class="pointer"/></td>
									    </tr>
										
									</table></td>
								  </tr>
								  <tr>
									<td >
									<table width="100%" border="0" cellpadding="0" cellspacing="1" class="gridtitle">
										<tr>
											<td  class="gridtitletitle">
											<div class="divcheck">&nbsp;</div>
											<div class="divtitle">Question</div>
											<div class="divaction">Action</div>											</td>
									    </tr>
											
										<tr >
										  <td >
										  <div id="changeNotificationNo"> </div>  
											<div id="sortlist">  												
												<?php  
													$i=1;													
													while ($row = $db->fetch($sql)) {  	
													
													if ($i % 2 == 1) $listitem = "griditem1";
												  	else $listitem = "griditem2";													
												?>
													<li class="<?=$listitem?>" onMouseOver="mOvr(this,'bgover')" onMouseOut="mOut(this,'<?=$listitem?>')" id="pictureId_<?=$row['id']?>">
													<div class="divcheck"><input type="checkbox" name="chkid" value="<?=$row["id"]?>" /></div>
													<div class="divtitle"><?=$row['question']?></div>
													<div class="divaction"> <img src="images/icons/edit.png" onclick="edit('<?=$row["id"]?>')" class="pointer"/>&nbsp;&nbsp;&nbsp;<img src="images/icons/del.png" onclick="del('<?=$row["id"]?>')" class="pointer" /></div>
													<div class="clr"></div>
													</li>
													
												<?		
														$i++;
													}  
												?>   
											</div>											</td>	
							            </tr>
									</table></td>
								  </tr>
								  <tr>
									<td><table width="100%" border="0" cellspacing="0">
										
										<tr>
										  <td colspan="2" align="left" valign="middle" class="titlepage"><?=$lb_tottalrow?>  <span class="numpage"><?=$totalrows?></span> </td>
										  <td colspan="3" align="right" valign="top" class="numpage"><? echo $paging->pagenew($totalrows, $perpage, $pagecount, $curpg, $gotopage, "","titlepage");?></td>
										</tr>

									</table></td>
								  </tr>
							  </table></td>
							</tr>
						</table></td>
					  </tr>
					  <tr>
						<td height="15" colspan="5"></td>
					  </tr>
				  </table>				  </td>
				</tr>
			</table></td>
			<td width="10" class="rightborder">&nbsp;</td>
		  </tr>
	  </table></td>
	</tr>
	<tr>
	  <td><table width="100%" border="0" cellpadding="0" cellspacing="0" class="dataBack">
		  <tr>
			<td width="34"><img src="<?=APPLICATION_SITEADMIN_URL?>images/cor_data_bot_l.gif" alt="bl" /></td>
			<td class="botborder" >&nbsp;</td>
			<td width="19"><img src="<?=APPLICATION_SITEADMIN_URL?>images/cor_data_bot_r.gif" alt="br" /></td>
		  </tr>
	  </table></td>
	</tr>
</table>
<input type="hidden" name="form_" value="delete" />		
<input type="hidden" name="listid" value="" />
<input type="hidden" name="curpg" value="<?=$curpg?>" />
</form>		
	
<?php
	$db->close();
?>
